/*
 * Copyright 2013 JROSE
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jrose.dao.jdbc;

import org.jrose.api.annotation.cache.CacheKey;
import org.jrose.api.annotation.cache.CacheKeyCandidate;
import org.jrose.api.annotation.cache.CacheKeyCandidates;
import org.jrose.api.annotation.cache.CacheSupport;
import org.jrose.api.annotation.cache.Cacheable;
import org.jrose.core.jdbc.persistence.AbstractUniquePrimaryKeyPersistence;
import org.jrose.core.jdbc.persistence.query.Criteria;
import org.jrose.core.jdbc.persistence.query.Query;
import org.jrose.entity.data.RoleCareer;

import javax.inject.Named;
import java.util.List;

/**
 * {@link RoleCareer} persistence implementation.
 *
 * @author Xiaohai Zhang
 * @since 2013-08-29 21:32
 */
@Named
@CacheSupport(RoleCareer.class)
@CacheKeyCandidates({
        @CacheKeyCandidate({
                @CacheKeyCandidate.EACH(name = "roleId", field = "roleId")
        })
})
public class RoleCareerPersistence extends AbstractUniquePrimaryKeyPersistence<RoleCareer, Long> {
    @Cacheable
    public List<RoleCareer> findByRoleId(@CacheKey("roleId") Long roleId) {
        Query<RoleCareer> query = createQuery().and(Criteria.where("roleId").is(roleId));
        return executeQuery(query);
    }
}
